package com.block.applet.service.impl;

/**
 * @author hekelong
 * @date 2025/10/16 下午4:52
 */

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.block.applet.service.OverdueRecordService;
import com.block.db.entity.OverdueRecord;
import com.block.db.entity.OverdueRecordInfo;
import com.block.db.mapper.OverdueRecordInfoMapper;
import com.block.db.mapper.OverdueRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

@Service
public class OverdueRecordServiceImpl implements OverdueRecordService {

    @Autowired
    OverdueRecordMapper overdueRecordMapper;
    @Autowired
    OverdueRecordInfoMapper overdueRecordInfoMapper;

    @Override
    public int addOverdueRecord(JSONObject tranData, Long uid) {
        OverdueRecord overdueRecord = new OverdueRecord();
        overdueRecord.setUserId(uid);
        overdueRecord.setOverdueType(tranData.getInteger("overdueType"));
        overdueRecord.setOverduePlatform(tranData.getString("overduePlatform"));
        overdueRecord.setOverdueAmount(tranData.getBigDecimal("overdueAmount"));
        overdueRecord.setOverdueTime(tranData.getInteger("overdueTime"));
        String nowDate = LocalDate.now().toString();
        overdueRecord.setDateInfo(nowDate);
        return overdueRecordMapper.insert(overdueRecord);
    }

    @Override
    public List<OverdueRecord> getOverdueRecordByUserId(Long uid) {
        // 根据用户ID查询逾期记录
        QueryWrapper<OverdueRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", uid);
        return overdueRecordMapper.selectList(queryWrapper);
    }

    @Override
    public List<OverdueRecordInfo> getOverdueRecordInfo() {
        return overdueRecordInfoMapper.getOverdueRecordInfo();
    }
}
